<?php
/**
 * [KeCms] Copyright (c) 2017 kecms.cn
 * [Author] King east ( 1207877378@qq.com )
 */

namespace app\admin\controller;


use app\admin\model\Admin;
use ke\Controller;
use think\Cache;
use think\Request;

class IndexController extends Controller
{
    public function index(Request $request)
    {
        $this->assign('data',[
            'admin'=>[
                'user'=>$request->adminInfo['user']
            ],
            'isLock'=>session('adminLock')
        ]);

        return $this->fetch();
    }

    public function home()
    {
        return $this->fetch();
    }

    /**
     * 清除缓存
     */
    public function clearCache()
    {
        Cache::clear();
        $this->success('缓存已经清空完成');
    }


    /**
     * 锁定/解锁 系统
     * @param Request $request
     */
    public function lockScreen(Request $request)
    {
        $type=input('get.type',0);
        if($type){
            // 锁定
            session('adminLock',1);
            $this->success('锁定成功');
        }else{
            // 解锁
            $num=session('adminLockNum');
            if($num>3){
                session('adminId',null);
                session('adminToken',null);
                $this->result([],-1,'密码多次输入错误,请重新登录.');
            }
            $pass=getForm('pass');
            $m=new Admin();
            if(!$m->chkPass($pass,$request->adminInfo['pass'],$request->adminInfo['private'])){
                session('adminLockNum',$num+1);
                $this->error('密码验证错误');
            }
            session('adminLock',null);
            $this->success('解锁成功');
        }
    }

}